//
//  BJDangShiXueXiViewController.m
//  DangXiao
//
//  Created by APPLE on 16/12/6.
//  Copyright © 2016年 APPLE. All rights reserved.
//

#import "BJDangShiXueXiViewController.h"
#import "BJTipHeaderTableViewCell.h"
#import "BJHeaderView.h"

@interface BJDangShiXueXiViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *myTableView;
@end

@implementation BJDangShiXueXiViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    if (_dangTuanShiWu == YES) {
        self.navigationItem.title = @"党团实务";
    }else{
    self.navigationItem.title = @"党史学习";
    }
}

//让分区头跟随tableView的滑动消失
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if (scrollView == self.myTableView){
        CGFloat sectionHeaderHeight = BILIHEIGHT(39); //区头高度
        if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y >=0) {
            scrollView.contentInset = UIEdgeInsetsMake(- scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
}

- (void)viewDidAppear:(BOOL)animated{
    self.navigationController.navigationBar.translucent = NO;
}

#pragma mark ---- 设置TbaleView
- (void)initUI{
    
    BJHeaderView *VIEW = [[BJHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, BILIHEIGHT(280))];
    _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight - 64) style:(UITableViewStylePlain)];
    _myTableView.delegate = self;
    _myTableView.dataSource = self;
    _myTableView.backgroundColor = GrayLabel;
    _myTableView.tableHeaderView = VIEW;
    
//    注册cell
    [_myTableView registerClass:[BJTipHeaderTableViewCell class] forCellReuseIdentifier:@"BJTipHeaderTableViewCell"];
    [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_myTableView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 16;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
    cell.textLabel.font = FontVlaue(15);
    cell.detailTextLabel.font = FontVlaue(15);
    cell.textLabel.text = @"爱神的箭番窠倒臼";
    cell.detailTextLabel.text = @"11-10";
    return cell;
}

static BJTipHeaderTableViewCell *cellView;
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (_dangTuanShiWu == NO) {
        cellView  = [[BJTipHeaderTableViewCell alloc]init];
        cellView.backgroundColor = GrayLabel;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapView:section:)];
        [cellView addGestureRecognizer:tap];
        return cellView;
    }else{
        return nil;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (_dangTuanShiWu == NO) {
        return BILIHEIGHT(39);
    }else{
        return 0.001;
    }
   
}


#pragma mark ---- 点击“分区头”
- (void)didTapView:(UITapGestureRecognizer *)tap section:(NSInteger)section{
    if (section == 0) {
        DLog(@"========");
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
